#include "common.hpp"

int main(void)
{
    APP::setup(true);

    ANIMATION *venus_loop   = new ANIMATION("./gfx/venus/venus.tga", 8);
    ANIMATION *tux          = new ANIMATION("./gfx/background/blah.pcx", 1);

    INPUT *joy1             = new INPUT(0);

    int venus_clock = 0;
    int tux_clock = 0;

    while(!key[KEY_ESC])
    {
        if (APP::is_time_for_logic())
        {
            // input
            INPUT::poll();

            // update logic
            tux_clock++;
            if(tux_clock >= 600) tux_clock = 0;
            venus_clock++;

            // draw
            APP::to_ortho();
            glColor3f(0.7f, 0.7f, 0.7f);
            tux->paint(tux_clock - 300, 300, 0, 600, 0, 0, ANIMATION::ADDITIVE);
            tux->paint(tux_clock + 300, 300, 0, 600, 0, 0, ANIMATION::ADDITIVE);
            tux->paint(tux_clock + 900, 300, 0, 600, 0, 0, ANIMATION::ADDITIVE);

            glColor3f(1.0f, 1.0f, 1.0f);
            tux->paint((tux_clock * 2), 0, 0, 600, 0, 0, ANIMATION::ADDITIVE);
            tux->paint((tux_clock * 2) + 600, 0, 0, 600, 0, 0, ANIMATION::ADDITIVE);
            tux->paint((tux_clock * 2),         600, 0, 600, 0, 0, ANIMATION::ADDITIVE);
            tux->paint((tux_clock * 2) + 600,   600, 0, 600, 0, 0, ANIMATION::ADDITIVE);

            venus_loop->paint(
                sinf(venus_clock / 33.0f) * 400 + 200,
                sinf(venus_clock / 41.0f) * 400 + 200,
                0, 64, sinf(venus_clock / 41.0f) * 400, (venus_clock / 7));

            venus_loop->paint(
                sinf(venus_clock / 35.0f) * 400 + 200,
                sinf(venus_clock / 29.0f) * 400 + 200,
                0, 64, 0, (venus_clock / 5));


            venus_loop->paint(
                sinf(venus_clock / 25.0f) * 100 + 185,
                sinf(venus_clock / 49.0f) * 100 + 300,
                0, 64, venus_clock / 1.5, (venus_clock / 5));

            venus_loop->paint(
                sinf(venus_clock / 89.0f) * 300 + 400,
                cosf(venus_clock / 19.0f) * 300 + 300,
                0, 64, -venus_clock, (venus_clock / 5));

            venus_loop->paint(
                sinf(venus_clock / 47.0f) * 400 + 200,
                cosf(venus_clock / 46.0f) * 400 + 200,
                0, 64, venus_clock, (venus_clock / 6));

            glColor4f(1,1,1, (sinf(venus_clock / 30.0f)) * 0.5 + 0.5 );
            venus_loop->paint(
                400,
                300,
                0, 128, TO_DEGREES(joy1->get_analogue_angle()), (venus_clock / 3), ANIMATION::SUBTRACTIVE);
            glColor4f(1,1,1, 1 );

            venus_loop->paint(
                256,
                256,
                0, 128, 90, (venus_clock / 7), ANIMATION::ALPHA);

            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            APP::gfx_printf(APP::get_game_font(), 128,64, 0, 32, -8, "*It works!!!*  %f", joy1->get_analogue_y());
            glDisable(GL_BLEND);

            APP::repaint();
            APP::logic_done();
        }
    }

    delete(joy1);
    delete(tux);
    delete(venus_loop);

    APP::shutdown();
}
END_OF_MAIN()
